﻿using System;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace NRadioTray.Plugin.MR
{
    /// <summary>
    /// Class <see cref="MrPluginView"/>.
    /// </summary>
    public partial class MrPluginView : Form, IMrPluginView
    {
        /// <summary>
        /// Observier field.
        /// </summary>
        private IMrPluginViewObserver observer;

        public MrPluginView()
        {
            this.InitializeComponent();
        }

        public bool OverrideList
        {
            get
            {
                return this.chbOverridePlaylist.Checked;
            }
        }

        /// <summary>
        /// Attaches the view observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        public void AttachViewObserver(IMrPluginViewObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            this.observer = observer;
        }

        public void SetLog(string text)
        {
            this.textBox1.Text.AppendLine(text);
        }

        /// <summary>
        /// BTNs the cancel click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BtnCancelClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnGetListClick(object sender, EventArgs e)
        {
            this.observer.GetList();
        }

        private void BtnSaveClick(object sender, EventArgs e)
        {
            this.observer.SaveList();
        }
    }

    public static class StringExtension
    {
        public static void AppendLine(this String text, string appendText)
        {
             text = new StringBuilder(text).AppendLine(appendText).ToString();
        }
    }
}